package com.study.decorator.logger;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;

public class JsonLogger extends LoggerDecorator {
    public JsonLogger(Logger logger) {
        super(logger);
    }

    @Override
    public void info(String msg) {
        JSONObject result = getJsonResult();
        result.put("msg",msg);
        logger.info(result.toString());
    }

    @Override
    public void error(String msg) {
        JSONObject result = getJsonResult();
        result.put("errmsg",msg);
        logger.error(result.toString());
    }

    public void error(Exception e){
        JSONObject result = getJsonResult();
        result.put("message",e.getMessage());
        result.put("stack",e.getStackTrace());
        logger.error(result.toString());
    }

    private JSONObject getJsonResult(){
        return new JSONObject();
    }
}
